package com.hzcc.hzccblog.utils;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.Random;

/**
 * @Author 早睡蛋
 * @Date 2022/7/11 21:03:40
 * @Desc:验证码工具类
 */
public class CodeUtil {
    private static char[] codeLetter = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
            'J', 'K', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
            'X', 'Y', 'Z','0','1', '2', '3', '4', '5', '6', '7', '8', '9','a','b','c','d','e','f','g','h','i','j','k','l','m'
            ,'n','o','p','q','r','s','t','u','v','w','x','y','z'};

    /**
     * 生成验证码
     * @return
     */
    public static String getCode(){
        Random random = new Random();
        String code = "";
        for (int i =0; i<6; i++){
            String oneCode = String.valueOf(codeLetter[random.nextInt(codeLetter.length)]);
            code+=oneCode;
        }
        return code;
    }
}
